<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Siteconfig extends MX_Controller
{
	protected $_templates;
	
	public function __construct()
	{
		parent::__construct();
		$this->pre_message ="";
		$this->load->config('config_site');
		$this->load->model('siteconfig_model','siteconfig');
		$this->load->helper('img') ;
		//$this->permit_library->check_permit();
		//$this->session->set_userdata(array('Url'=>uri_string()));           
	}
	
	function index()
	{
		$data['title'] = 'Cấu hình hệ thống';
		$data['site_name'] = $this->config->item('site_name');
		$data['site_address'] = $this->config->item('site_address');
		$data['site_phone'] = $this->config->item('site_phone');
		$data['hotline'] = $this->config->item('hotline');
		
		$data['address2'] = $this->config->item('address2');
		$data['phone2'] = $this->config->item('phone2');
		
		$data['site_url'] = $this->config->item('site_url');
		$data['site_email'] = $this->config->item('site_email');
		$data['masothue'] = $this->config->item('masothue');
		$data['vietcombank'] = $this->config->item('vietcombank');
		//$data['site_email'] = $this->config->item('site_email');
		$data['site_keyword'] = $this->config->item('site_keyword');
		$data['site_des'] = $this->config->item('site_des');
		//$data['site_time'] = $this->config->item('site_time');
		
		if(isset($_POST['bt_submit']))
		{
			$this->form_validation->set_rules('site_name','Tên Website','trim|required');
			$this->form_validation->set_rules('site_keyword','Từ khóa','trim|required');
			if($this->form_validation->run() == FALSE){
				$this->pre_message = validation_errors();
			}else{
				 $str = "<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');\n/**\n* Cache file for siteconfig lv8x.com.\n* Date: ".date('d/m/y H:i:s').".\n**/";
				$site_name = $this->input->post('site_name');
				$site_address = $this->input->post('site_address');
				$site_phone = $this->input->post('site_phone');
				$address2 = $this->input->post('address2');
				$phone2 = $this->input->post('phone2');
				$hotline = $this->input->post('hotline');
				$site_url = $this->input->post('site_url');
				$site_email = $this->input->post('site_email');
				$site_des = $this->input->post('site_des');
				$site_keyword = $this->input->post('site_keyword');
				$vietcombank = $this->input->post('vietcombank');
				$masothue = $this->input->post('masothue');
				
				$str .= "\n";
				$str .= "\n\$config['site_name'] = '$site_name';";
				$str .= "\n\$config['site_address'] = '$site_address';";
				$str .= "\n\$config['site_phone'] = '$site_phone';";
				$str .= "\n\$config['address2'] = '$address2';";
				$str .= "\n\$config['phone2'] = '$phone2';";
				$str .= "\n\$config['site_url'] = '$site_url';";
				$str .= "\n\$config['site_email'] = '$site_email';";
				$str .= "\n\$config['hotline'] = '$hotline';";
				$str .= "\n\$config['masothue'] = '$masothue';";
				$str .= "\n\$config['vietcombank'] = '$vietcombank';";
				$str .= "\n\$config['site_des'] = '$site_des';";
				$str .= "\n\$config['site_keyword'] = '$site_keyword';";
				$str .= "\n\n/* End of file siteconfig lv8x.com*/\n/* Location: ./data/config_site.php */";
			
				write_file('../data/config_site.php', $str);   
				$this->session->set_flashdata('message','Lưu thành công');
				redirect('cauhinh');               
			}     
		}
		    
		$data['message'] = $this->pre_message;
		$data['page'] = 'siteconfig/index';
		$this->load->view('layout/skin',$data);
	}
	
	/*function config(){
		$this->load->view('siteconfig/config',$data);
	}
	
	function php_info(){
		$data['title'] = 'Cấu hình PHP';
		$data['array'] = $this->siteconfig->phpinfo_array( 4, 1 );
		$this->_templates['page'] = 'siteconfig/phpinfo';
		$this->site->load($this->_templates['page'],$data);
	}*/
}
?>
